package com.rules.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gillion.grule.client.utils.Holidays;

import com.rules.admin.dao.HolidaysModelDao;
import com.rules.admin.entity.HolidaysModel;
import com.rules.admin.redis.ZookeeperNotifer;
import com.rules.admin.service.HolidaysService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Service
public class HolidaysServiceImpl extends ServiceImpl<HolidaysModelDao, HolidaysModel> implements HolidaysService {

   @Autowired
   public ZookeeperNotifer zookeeperNotifer;

   public IPage<HolidaysModel> queryPage(String time, IPage<HolidaysModel> page) {
      LambdaQueryWrapper<HolidaysModel> queryWrapper = new LambdaQueryWrapper<>();
      if (StringUtils.isNotBlank(time)) {
         queryWrapper.like(HolidaysModel::getHoliday,"%" + time + "%");
      }
      return this.page(page, queryWrapper);

   }

   public List<HolidaysModel> selectAll() {
      return this.list();
   }

   public void publish() {
      List<HolidaysModel> list = this.selectAll();
      Holidays.holidays = new ArrayList();
      Iterator var2 = list.iterator();

      while(var2.hasNext()) {
         HolidaysModel holidaysModel = (HolidaysModel)var2.next();
         com.gillion.grule.client.core.HolidaysModel holidaysModelClient = new com.gillion.grule.client.core.HolidaysModel();
         holidaysModelClient.setHoliday(holidaysModel.getHoliday());
         holidaysModelClient.setType(holidaysModel.getType());
         Holidays.holidays.add(holidaysModelClient);
      }

      this.zookeeperNotifer.holidaysPublish();
   }
}
